package mygang.helper;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import mygang.model.BaseModel;
import mygang.model.CustomResponse;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 13/08/2012
 */
public class ControllerHelper extends BaseModel {

    public ControllerHelper(){}
    
    public static void handleException(Exception ex, HttpServletResponse response) throws IOException{
        log.error("Error occurred: "+ex.getMessage());
        ex.printStackTrace();
        
        CustomResponse result = new CustomResponse(
                CustomResponse.Result.FAILURE, 
                "", 
                ex.getCause().getMessage(), 
                ex.getMessage());
        
        JsonHelper.prepareJsonResponse(result, response);
    }
    
    public static void success(HttpServletResponse response) throws IOException{
        CustomResponse result = new CustomResponse(CustomResponse.Result.SUCCESS);
        JsonHelper.prepareJsonResponse(result, response);
    }

}